/*	
 *  -- ************************************************************
 -- Author		:	PUY
 -- Create date	:	-
 -- Update date	:	PUY
 -- Update By	:   29-07-2011
 -- Description	:	
 -- ************************************************************
 */
package com.app.DB;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Types;

public class SegwayDetails {
	
	public SegwayDetails() {
		SegwayName = SegwayTimeUse = SegwayStatus = Latitude = 
		Longtitude = UserName = Message = IsMessage = ServerMessage = PicPath = "";
	 }	
    public SegwayDetails(
            String OID,
            String UsrOpt,
            String IsActive,
            String IsDeleted,
            
            String SegwayName,
            String SegwayTimeUse,
            String SegwayStatus,
            String Latitude,
            String Longtitude,
            String UserName,
            String Message,
            String IsMessage,
            String ServerMessage,
            String PicPath
            )
    
   {
        this.OID 					= OID;
        this.UsrOpt 				= UsrOpt;
        this.IsActive 				= IsActive;
        this.IsDeleted 				= IsDeleted;
        this.SegwayName 			= SegwayName;
        this.SegwayTimeUse 			= SegwayTimeUse;
        this.SegwayStatus 			= SegwayStatus;
        this.Latitude 				= Latitude;
        this.Longtitude 			= Longtitude;
        this.UserName				= UserName;
        this.Message 				= Message;
        this.IsMessage 				= IsMessage;
        this.ServerMessage 			= ServerMessage;
        this.PicPath 				= PicPath;

    }
    //-------------------- Variable -------------------------
    private String OID,
    		UsrOpt,
    		IsActive,
    		IsDeleted,
    		SegwayName,
    		SegwayTimeUse,
    		SegwayStatus,
    		Latitude,
    		Longtitude,
    		UserName,
    		Message,
    		IsMessage,
    		ServerMessage,
    		PicPath;
            
    

    Connect con = new Connect(); 
    Connection conn = con.Connect();
    ResultSet rs = null;

    // -------------------- GET-SET -------------------------
    
 
	public String getUsrOpt() {
		return UsrOpt;
	}

	public String getPicPath() {
		return PicPath;
	}
	public void setPicPath(String picPath) {
		PicPath = picPath;
	}
	public String getIsMessage() {
		return IsMessage;
	}
	public void setIsMessage(String isMessage) {
		IsMessage = isMessage;
	}
	public String getServerMessage() {
		return ServerMessage;
	}
	public void setServerMessage(String serverMessage) {
		ServerMessage = serverMessage;
	}
	public String getMessage() {
		return Message;
	}
	public void setMessage(String message) {
		this.Message = message;
	}
	public void setUsrOpt(String usrOpt) {
		UsrOpt = usrOpt;
	}
	
    public String getOID() {
		return OID;
	}

	public void setOID(String oID) {
		OID = oID;
	}

	
	public String getSegwayName() {
		return SegwayName;
	}
	public void setSegwayName(String segwayName) {
		SegwayName = segwayName;
	}
	public String getSegwayTimeUse() {
		return SegwayTimeUse;
	}
	public void setSegwayTimeUse(String segwayTimeUse) {
		SegwayTimeUse = segwayTimeUse;
	}
	public String getSegwayStatus() {
		return SegwayStatus;
	}
	public void setSegwayStatus(String segwayStatus) {
		SegwayStatus = segwayStatus;
	}
	public String getLatitude() {
		return Latitude;
	}
	public void setLatitude(String latitude) {
		Latitude = latitude;
	}
	public String getLongtitude() {
		return Longtitude;
	}
	public void setLongtitude(String longtitude) {
		Longtitude = longtitude;
	}
	public String getUserName() {
		return UserName;
	}
	public void setUserName(String userName) {
		UserName = userName;
	}
	public String getIsActive() {
		return IsActive;
	}

	public void setIsActive(String isActive) {
		IsActive = isActive;
	}

	public String getIsDeleted() {
		return IsDeleted;
	}

	public void setIsDeleted(String isDeleted) {
		IsDeleted = isDeleted;
	}


	//-------------------- SQL ------------------------
    public ResultSet selectSegwayDetails(String StrSearch,String StrUserName) throws Exception {
        String StrSql = "SELECT [OID],"
                + "[LastModified],"
                + "[ModifiedDate],"
                + "[ModifiedTime],"
                + "[ModifiedBy],"
                + "[UserModified],"
                + "[CreatDate],"
                + "[CreatTime],"
                + "[CreatedBy],"
                + "[UserCreate],"
                + "[IsActive],"
                + "[IsDeleted],"
                
                + "[SegwayName],"
                + "[SegwayTimeUse],"
                + "[SegwayStatus],"
                + "[Latitude],"
                + "[Longtitude],"
                + "[UserName],"
                + "[Message],"
                + "[IsMessage],"
                + "[ServerMessage],"
                + "[PicPath] "
  				+ "FROM [MegaAutoCare].[dbo].[udfSegwayDetails]() "
  
                + "WHERE [IsDeleted]='0' "; 

        
        if (!StrUserName.equals("")) {
            StrSql += " AND [UserName] LIKE '" + StrUserName + "' ";
        }

        if (!StrSearch.equals("")) {
            StrSql += " AND [UserName] LIKE '%" + StrSearch + "%' OR [OID] LIKE '" + StrSearch + "' " ;
        }

//        return sqlsel.getReSultSQL(StrSql);
        return con.selectData(StrSql);
    }

    public String OperationData(String OperationType) throws Exception {
        try {
//        		conn = objConnection.getConnection();
        		conn = con.Connect();
                java.sql.CallableStatement cstmt = conn.prepareCall("{call stpSegwayDetailsManagement(?,?,?,?,? ,?,?,?,?,? ,?,?,?,?,? ,?)}");
                
                cstmt.setString(1, OperationType);
                cstmt.setString(2, getOID());
                cstmt.setString(3, getUsrOpt());
                cstmt.setString(4, getIsActive());
                cstmt.setString(5, getIsDeleted());

                cstmt.setString(6, getSegwayName());
                cstmt.setString(7, getSegwayTimeUse());
                cstmt.setString(8, getSegwayStatus());
                cstmt.setString(9, getLatitude());
                cstmt.setString(10, getLongtitude());
                
                cstmt.setString(11, getUserName());
                cstmt.setString(12, getMessage());
                cstmt.setString(13, getIsMessage());
                cstmt.setString(14, getServerMessage());
                cstmt.setString(15, getPicPath());
                
                cstmt.registerOutParameter(16, Types.VARCHAR);
                cstmt.execute();
                return cstmt.getString(16);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (conn != null) {
                conn.close();
            }
        }
        return null;
    }
}
